﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InformationSystem.Dao;
using InformationSystem.Entity;

namespace InformationSystem
{
    public partial class Login : Form
    {
        private UserDao uDao = new UserDao();

        public Login()
        {
            InitializeComponent();
        }

        private void btQuit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            String name = tbName.Text.Trim();
            String pwd = tbPwd.Text.Trim();

            if(name == "" || pwd == "")
            {
            	MessageBox.Show("name or password cannot be empty");
            	return;
            }
            
            
            User user = new User();
            user.name = name;
            user.pwd = pwd;


            if (uDao.validUser(user))
            {
                AdminPanel a = new AdminPanel();
                a.Show();

                this.Visible = false;
            }
            else
            {
                MessageBox.Show("Name or password is incorrect!");
            }
        }

        private void Login_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
        
        
		void TbPwdKeyPress(object sender, KeyPressEventArgs e)
		{
			if(e.KeyChar == '\r')
			{
				btLogin_Click(sender,e);
			}
			
		}
		
        
    }
}
